﻿function Get-TSMColumns {
    <#
        .SYNOPSIS
            Get TSM DB2 columns
                    
        .DESCRIPTION
            The Get-TSMColumns returns columns in DB2

        .EXAMPLE
            Get-TSMColumns

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 09/01/2015
    #>
    [CmdletBinding()]
    Param(        
        [Parameter(Position=0)]
        $ColumnName,

        [Parameter(Position=1)]
        $TableName,
        
        [Parameter(Position=2)]
        $Schema
    )

    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "COLNAME";   "Operator" = "LIKE"; "Value" = $ColumnName }
    $whereProps += [PSCustomObject]@{ "Column" = "TABNAME";   "Operator" = "LIKE"; "Value" = $TableName }
    $whereProps += [PSCustomObject]@{ "Column" = "TABSCHEMA"; "Operator" = "LIKE"; "Value" = $Schema }

    $query = Format-TSMQuery -Table "COLUMNS" -Where $whereProps -OrderBy "COLNAME,TABNAME"
    $result = Invoke-TSMCommand -Command $query

    $defaultDisplaySet = 'TABSCHEMA','TABNAME','COLNAME'
    $typeDefinitions = @{
                        "CREATE_TIME" = [DateTime]
                        "COLNO"       = [Int32]
                        "LENGTH"      = [Int32]
                        "SCALE"       = [Int32]
						"NULLS"       = [bool]
                        }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet
}